import 'babel-polyfill'
import Vue from 'vue'
import VueLazyload from 'vue-lazyload'
import router from './routes'
import store from './store'
import './components'
import 'css/base.scss'
import '../static/jquery.form'
import '../static/jquery.qrcode.min'
import './common/filters'
import { session, storage } from './common/util'

Vue.use(VueLazyload, {
  attempt: 1
})

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  // 判断浏览器是PC还是wap端
  if (/Android|webOS|iPhone|iPad|BlackBerry/i.test(navigator.userAgent)) {
    window.location.href = 'https://wap.haoxiadan.cn/'
  }
  if (to.meta.isAuth) {
    const userInfo = session.get('userInfo') || storage.get('userInfo') || {}
    if (userInfo.accessToken) {
      next()
    } else {
      window.$toast('亲，请先登录', () => {
        next({
          path: `/login`
        })
      })
    }
  } else {
    next()
  }
})

// 初始化JMessage
window.JIM = new JMessage({
  // debug: true
})
store.dispatch('JIMInit', {})

export default new Vue({
  el: '#app',
  router,
  store
})
